package com.hwl.demo1.factory;

import com.hwl.demo1.service.CashSuper;
import com.hwl.demo1.service.impl.CashNormal;
import com.hwl.demo1.service.impl.CashRebate;
import com.hwl.demo1.service.impl.CashReturn;

import java.util.Scanner;

/**
 * 收费工厂
 *
 * @author sentry
 * @since 2023-02-25
 */
public class CashFactory {

    public static CashSuper createCashAccept(int cashType) {
        CashSuper cs;
        switch (cashType) {
            case 2:
                cs = new CashRebate(0.8d);
                break;
            case 3:
                cs = new CashRebate(0.5d);
                break;
            case 4:
                cs = new CashReturn(300d, 100d);
                break;
            default:
                cs = new CashNormal();
        }

        return cs;
    }

    public static void main(String[] args) {
        double price;
        int num;
        int cashType;
        try {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入商品单价：");
            price = Double.parseDouble(sc.nextLine());
            System.out.println("请输入商品数量：");
            num = Integer.parseInt(sc.nextLine());
            System.out.println("请输入优惠类型：");
            cashType = Integer.parseInt(sc.nextLine());
        } catch (Exception e) {
            throw new RuntimeException("输入有误 " + e);
        }

        CashSuper cSuper = CashFactory.createCashAccept(cashType);
        double total = cSuper.acceptCash(price, num);
        System.out.println("价格为：" + total);
    }
}
